import axios from "axios"
import api from './index'

let token  = localStorage.getItem('TOKEN')
// 网络请求接口列表
//  在vue3项目中 axios 关于post请求，注意文档类型
// 接口1：管理员登录
// http://localhost:3000/admin/login
export const singin = async (data={})=> {
    return axios.post(
        `${api.url}/admin/login`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口2：验证码
// http://localhost:3000/api/verify/test
export const test = async (data={})=> {
    return axios.get(
        `${api.url}/api/verify/test`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口3: 用户列表
// http://localhost:3000/admin/userlist
export const userList = (data={})=>{
    // 获取用户的token
    // let token:string | null | any  = localStorage.getItem('AUTO_TOKEN')
    return axios.get(`${api.url}/admin/userlist`,{params: data,headers:{token}})
}

// 接口4 删除用户
// http://127.0.0.1:3000/admin/delete
export const deleteUserFunc = (data={})=>{
    return axios.post(`${api.url}/admin/delete`,data,{headers:{token}})
}

// 接口5 轮播图列表
// http://127.0.0.1:3000/banner/list
export const listBannerFunc = (data={})=>{
    return axios.get(`${api.url}/banner/list`,{params: data , headers:{token}})
}

// 接口6 删除轮播图
// http://127.0.0.1:3000/banner/remove
export const removeBannerFunc = (data={})=>{
    return axios.post(`${api.url}/banner/remove`,data,{headers:{token}})
}

// 接口7 获取导航列表
// http://127.0.0.1:3000/navs/list
export const listNavFunc = (data={})=>{
    return axios.get(`${api.url}/navs/list`,{params: data , headers:{token}})
}

// 接口8 删除导航
// http://127.0.0.1:3000/navs/remove
export const removeNavFunc = (data={})=>{
    return axios.post(`${api.url}/navs/remove`,data,{headers:{token}})
}

// 接口9 发布轮播图
// http://127.0.0.1:3000/banner/add
export const addBannerFunc = (data={})=>{
    return axios.post(`${api.url}/banner/add`,data,{headers:{token}})
}

// 接口10 删除图片
// http://127.0.0.1:3000/photo/delete
export const removePhotoFunc = (data={})=>{
    return axios.post(`${api.url}/photo/delete`,data)
}

// 接口11 上传图片
// http://127.0.0.1:3000/photo/preview
export const addPhotoFunc = (data={})=>{
    return axios.post(`${api.url}/photo/preview`,data,{headers:{token}})
}

// 接口12 添加导航
// http://127.0.0.1:3000/navs/add
export const addNavFunc = (data={})=>{
    return axios.post(`${api.url}/navs/add`,data,{headers:{token}})
}

// 接口13 发布文章
// http://127.0.0.1:3000/article/add
export const addArticleFunc = (data={})=>{
    return axios.post(`${api.url}/article/add`,data,{headers:{token}})
}

// 接口14 文章列表
// http://127.0.0.1:3000/article/list
export const listArticleFunc = (data={})=>{
    return axios.get(`${api.url}/article/list`,{params: data , headers:{token}})
}
// 接口15 删除文章
// http://127.0.0.1:3000/article/remove
export const removeArticleFunc = (data={})=>{
    return axios.post(`${api.url}/article/remove`,data,{headers:{token}})
}

// 接口16 获取管理员的头像
// http://127.0.0.1:3000/admin/get_picUrl
export const getAdminPicUrl = (data={})=>{
    return axios.get(`${api.url}/admin/get_picUrl`,{params: data , headers:{token}})
}